<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>oop8(原型-继承的三种方式)</title>
</head>
<body>
<script type="text/javascript">
	
	//原型-继承
	/*
	//父类
	function Person (name, age) {
		this.name = name;
		this.age = age;
	}

	Person.prototype.id = 6100001;
	//子类
	function Boy (sex) {
		this.sex = sex;
	}

	Boy.prototype = new Person('z3', 20);

	var b = new Boy('男');

	alert(b.name);
	*/

	//构造函数集成【类继承】（只继承模版，不继承原型）
	/*
	//父类
	function Person (name, age) {
		this.name = name;
		this.age = age;
	}

	Person.prototype.id = 6100001;

	//子类
	function Boy (name, age, sex) {
		Person.call(this, name, age);
		this.sex = sex;
	}

	var b1 = new Boy('z4', 20, '男');

	alert(b1.name);
	//alert(b1.id); //undefined
	*/

	//混合继承（原型继承和构造函数集成一起使用）

	//父类
	function Person (name, age) {
		this.name = name;
		this.age = age;
	}

	Person.prototype.id = 6100001;
	Person.prototype.getName = function () {
		alert(this.name);
	}

	//子类
	function Boy (name, age, sex) {
		Person.call(this, name, age);
		this.sex = sex;
	}

	Boy.prototype = new Person();

	var b2 = new Boy('z5', 30, '男');

	alert(b2.name);
	b2.getName();

</script>
</body>
</html>